/**
 * Title:		GoldTester.java
 * Description: This java file is responsible for the critical Semantic Testing
 * 				procedure. The filenames (filename.debug and filename.gold) 
 * 				passed by the Tester class are fetched and their contents are 
 * 				loaded in memory as a Vector data structure. Two different data
 * 				structures pertain to .debug and .gold files correspondingly. 
 * 				The contents of the 2 data structures are then compared by
 * 				traversing over the delimiter '#'. If the content do match, 
 * 				then the result is 'PASS', else it is 'FAIL'. 
 * 
 * @version		1.0 April 2009
 * @author		Gaurav Pandey
 */

import java.util.*;
import java.io.*;

class GoldTester
{	private Vector<String> vecDebug;
	private Vector<String> vecGold;
	private int xPondSize,yPondSize;
	private String pondColor;
	private int debugCount,goldCount;
	private int xGoldPondSize,yGoldPondSize;
	private String goldPondColor;
	private int pond = 0,frog = 0;
	
	/**Constructor to intialize the variables and Vector Data Structure*/
	public GoldTester()
	{	vecDebug = new Vector<String>();
		vecGold = new Vector<String>();
		xPondSize = 300;
		yPondSize = 300;
		debugCount = 0;
		goldCount = 0;
		xGoldPondSize = 0;
		yGoldPondSize = 0;
		pondColor = "white";
		goldPondColor = "";
		for(int i=0;i<100000;i++)
		{	vecDebug.add("");
			vecGold.add("");
		}
	}
	
	/**clearer function is used to erase the contents of certain variables and 
	 * vector data structures specified within it and reinitialize them.*/
	public void clearer() {
		System.out.println("clear");
		vecDebug.removeAllElements();
		vecGold.removeAllElements();
		xPondSize = 0;
		yPondSize = 0;
		debugCount = 0;
		goldCount = 0;
		xGoldPondSize = 0;
		yGoldPondSize = 0;
		pondColor = "";
		goldPondColor = "";
	}
	
	/**debug function fetches the debug statements from the .debug file and 
	 * loads it into a 'debug-vector' data structure for further processing*/
	public void debug(String debugString)
	{	StringTokenizer str, strDelim, strNew;
		String debugStr = "", s = "", pondDelim = "";
		String openBrace = "",neww = "",frogg = "";
		int id = 0;
		try
		{	FileReader debugFileReader = new FileReader("validation/" +
				"semantics/test-output/"+debugString);
			BufferedReader debugBufferedReader = new BufferedReader(
					debugFileReader);
			if((s=debugBufferedReader.readLine())!=null)
			{	str = new StringTokenizer(s);
				str.nextToken();
				pondDelim = str.nextToken();
				if(pondDelim.contains(","))
				{	strDelim = new StringTokenizer(pondDelim,",");
					xPondSize = Integer.parseInt(strDelim.nextToken());
					yPondSize = Integer.parseInt(strDelim.nextToken());
				}
			}
			
			while((s=debugBufferedReader.readLine())!=null)
			{	if(!s.isEmpty())
				{	if(s.contains("pondcolor"))
					{	str = new StringTokenizer(s);
						str.nextToken();
						pondColor = str.nextToken();
					}
					if(s.contains("new"))
					{	strNew = new StringTokenizer(s);
						id = Integer.parseInt(strNew.nextToken());
						neww = strNew.nextToken();
						frogg = strNew.nextToken();
						openBrace = strNew.nextToken();
						vecDebug.set(id,id+" "+neww+" "+frogg+"#"
								+openBrace+"#");
						debugCount++;
					}
					else if(s.contains("frogcolor") || s.contains("speed") 
							|| s.contains("forward") || s.contains("turnleft")
							||s.contains("turnright"))
					{	strNew = new StringTokenizer(s);
						id = Integer.parseInt(strNew.nextToken());
						debugStr = vecDebug.get(id);
						vecDebug.set(id,debugStr+id+" "+strNew.nextToken()+" "
								+strNew.nextToken()+"#");
					}	
					else if(/**s.contains("clearscreen") || s.contains("reset") 
					|| s.contains("startdraw") || s.contains("stopdraw") ||*/ 
							s.contains("center"))
					{	strNew = new StringTokenizer(s);
						id = Integer.parseInt(strNew.nextToken());
						debugStr = vecDebug.get(id);
						vecDebug.set(id,debugStr+id+" "+strNew.nextToken()+"#");
					}
					else if(s.contains("rightcurve") || s.contains("leftcurve"))
					{	strNew = new StringTokenizer(s);
						id = Integer.parseInt(strNew.nextToken());
						debugStr = vecDebug.get(id);
						vecDebug.set(id,debugStr+id+" "+strNew.nextToken()+" "
								+strNew.nextToken()+"#");
					}
					else if(s.contains("goto"))
					{	strNew = new StringTokenizer(s);
						id = Integer.parseInt(strNew.nextToken());
						debugStr = vecDebug.get(id);
						vecDebug.set(id,debugStr+id+" "+strNew.nextToken()+" "+
								strNew.nextToken()+"#");
					}
					else if(s.contains("startdraw"))
					{	strNew = new StringTokenizer(s);
						id = Integer.parseInt(strNew.nextToken());
						debugStr = vecDebug.get(id);
						vecDebug.set(id,debugStr+id+" "+strNew.nextToken()+"#");
					}
					else if(s.contains("stopdraw"))
					{	strNew = new StringTokenizer(s);
						id = Integer.parseInt(strNew.nextToken());
						debugStr = vecDebug.get(id);
						vecDebug.set(id,debugStr+id+" "+strNew.nextToken()+"#");
					}
					else if(s.contains("}"))
					{	strNew = new StringTokenizer(s);
						id = Integer.parseInt(strNew.nextToken());
						debugStr = vecDebug.get(id);
						vecDebug.set(id,debugStr+id+" "+strNew.nextToken()+"#");
					}
				}
			}
			debugBufferedReader.close();
			debugFileReader.close();
		}
		catch(Exception e)
		{	System.err.println("Exception error in Debug: "+e.getMessage());
		}
	}
	
	/**gold function is responsible for parsing the gold standard representation
	 * into an intermediate representation and load it in a Gold Vector Data 
	 * Structure for further processing*/
	public void gold(String goldString)
	{	StringTokenizer strPond;
		String s = "",ss = "",frogColor = "",frogAction = "",frogCurve = "";
		int frogID = 0,frogSpeed = 0,frogValueMin = 0,frogValueMax = 0;
		int frogValue = 0,frogRadius = 0,frogRadiusMin = 0,frogRadiusMax = 0;
		int frogDegree = 0,frogDegreeMin = 0,frogDegreeMax = 0;
		int frogX=0,frogXMin = 0,frogXMax = 0,frogY=0,frogYMin = 0,frogYMax = 0;

		try
		{	FileReader goldFileReader = new FileReader(goldString);
			BufferedReader goldBufferedReader = new BufferedReader
					(goldFileReader);
			while((ss=goldBufferedReader.readLine())!=null)
			{	s=ss.trim();
				if(!s.isEmpty())
				{	if(s.startsWith("<pond"))
					{	if(s.endsWith(">"))
						{	strPond = new StringTokenizer(s);
							if((strPond.countTokens()!=4 || !s.contains("xsize")
									|| !s.contains("ysize") || 
									!s.contains("color")) && 
									(strPond.countTokens()!=3 || 
											!s.contains("xsize") || 
											!s.contains("ysize"))) {
								System.err.println("Incomplete or Incorrect " +
										"parameters in <pond> construct in " +
										"Gold Test File");
							}
							else {
								Vector<String> vecPond = new Vector<String>();	
								if(strPond.countTokens()==3) {
									strPond.nextToken();
									vecPond.add(strPond.nextToken());
									vecPond.add(strPond.nextToken());
									goldPondColor = "white";
								}
								else {
									strPond.nextToken();
									vecPond.add(strPond.nextToken());
									vecPond.add(strPond.nextToken());
									vecPond.add(strPond.nextToken());
								}
				
								
								for(int i = 0;i<vecPond.size();i++)
								{	String vecStrPond = vecPond.elementAt(i).
									toString();
									if(vecStrPond.startsWith("xsize="))
									{	strPond = new StringTokenizer
												(vecStrPond,"\"");
										strPond.nextToken();
										try {
										xGoldPondSize = Integer.parseInt
												(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'xsize' of " +
													"<pond> construct is not " +
													"an Integer. Reverting " +
													"the value to 'default' 0");
											xGoldPondSize=300;
										}
									}
									if(vecStrPond.startsWith("ysize="))
									{	strPond = new StringTokenizer
											(vecStrPond,"\"");
										strPond.nextToken();
										try {
										yGoldPondSize = Integer.parseInt
											(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'ysize' of " +
													"<pond> construct is not " +
													"an Integer. Reverting " +
													"the value to 'default' 0");
											yGoldPondSize=300;
										}
									}
									if(vecStrPond.startsWith("color="))
									{	strPond = new StringTokenizer
											(vecStrPond,"\"");
										strPond.nextToken();
										try {
										goldPondColor = strPond.nextToken().
											toString();
										}
										catch(Exception e) {
											goldPondColor = "white";
										}
										if(goldPondColor.equalsIgnoreCase("red")
												|| goldPondColor.
												equalsIgnoreCase("blue") || 
												goldPondColor.
												equalsIgnoreCase("green") || 
												goldPondColor.
												equalsIgnoreCase("yellow") || 
												goldPondColor.
												equalsIgnoreCase("white") || 
												goldPondColor.
												equalsIgnoreCase("black"))
										{}
										else {
											System.err.println("Incorrect " +
													"Color Specified! " +
													"Reverting to default \"" +
													"white\" color for pond");
											goldPondColor = "white";
										}
									}
								}
							pond++;
							}
						}
						else {
							System.err.println("Syntax Error in <pond> " +
									"construct in Gold Test File");
						}
					}
					else if(s.startsWith("<frog "))
					{	if(s.endsWith(">")) {
							strPond = new StringTokenizer(s);
							
							if(strPond.countTokens()!=2 || !s.contains("id")) {
								System.err.println("Incomplete or Incorrect " +
										"parameters in <frog> construct in " +
										"Gold Test File");
							}
							else {

								strPond.nextToken();
								Vector<String> vecPond = new Vector<String>();
								vecPond.add(strPond.nextToken());
					
								for(int i = 0;i<vecPond.size();i++)
								{	String vecStrPond = vecPond.
										elementAt(i).toString();
									
									if(vecStrPond.startsWith("id="))
									{	strPond = new StringTokenizer
											(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogID = Integer.parseInt
												(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'frogID' " +
													"of <frog> construct is" +
													" not an Integer. " +
													"Reverting the value " +
													"to 'default' 1");
											frogID=1;
										}
									}
								}
								frog++;
								goldCount++;
								vecGold.set(frogID, frogID+" new Frog"
										+"#"+"{"+"#");
							}
						}
						else {
							System.err.println("Syntax Error in <frog> " +
									"construct in Gold Test File");
						}
					}
					else if(s.startsWith("</frogspeed"))
					{	if(s.endsWith(">")) {
							strPond = new StringTokenizer(s);
							if(strPond.countTokens()!=2 || 
									!s.contains("value")) {
								System.err.println("Incomplete or Incorrect" +
										" parameters in </frogspeed> " +
										"construct in Gold Test File");
							}
							else {
								strPond.nextToken();
								Vector<String> vecPond = new Vector<String>();
								vecPond.add(strPond.nextToken());
					
								for(int i = 0;i<vecPond.size();i++)
								{	String vecStrPond = vecPond.
										elementAt(i).toString();
									if(vecStrPond.startsWith("value="))
									{	strPond = new StringTokenizer
											(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogSpeed = Integer.
												parseInt(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'frogSpeed' " +
													"of <frog> construct is " +
													"not an Integer. " +
													"Reverting the value " +
													"to 'default' 1");
											frogSpeed=3;
										}
										if(frogSpeed<1 || frogSpeed>5)
											frogSpeed=3;
									}
								}
								vecGold.set(frogID, vecGold.get(frogID)+
										frogID+" speed "+frogSpeed+"#");
							}
						}
						else {
							System.err.println("Syntax Error in </frogspeed>" +
									" construct in Gold Test File");
						}
					}
					else if(s.startsWith("</frogcolor"))
					{	if(s.endsWith(">")) {
							strPond = new StringTokenizer(s);
							if(strPond.countTokens()!=2 || 
									!s.contains("value")) {
								System.err.println("Incomplete or Incorrect" +
										" parameters in </frogcolor> " +
										"construct in Gold Test File");
							}
							else {
								strPond.nextToken();
								Vector<String> vecPond = new Vector<String>();
								vecPond.add(strPond.nextToken());
					
								for(int i = 0;i<vecPond.size();i++)
								{	String vecStrPond = vecPond.
									elementAt(i).toString();
									if(vecStrPond.startsWith("value="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogColor = 
												strPond.nextToken().toString();
										}
										catch(Exception e) {
											frogColor="blue";
										}
										if((frogColor.equalsIgnoreCase("red") || 
											frogColor.equalsIgnoreCase("blue") 
											|| 
											frogColor.equalsIgnoreCase("green") 
											|| 
											frogColor.equalsIgnoreCase("yellow") 
											|| 
											frogColor.equalsIgnoreCase("white") 
											|| 
											frogColor.equalsIgnoreCase("black"))
												)
										{}
										else {
											System.err.println("Incorrect " +
													"Color Specified! " +
													"Reverting to default" +
													" \"blue\" color for frog");
											frogColor = "blue";
										}
									}
								}
								vecGold.set(frogID, vecGold.get(frogID)+
										frogID+" frogcolor "+frogColor+"#");
							}
						}
						else {
							System.err.println("Syntax Error in </frogcolor> " +
									"construct in Gold Test File");
						}
					}
					else if(s.startsWith("</action"))
					{	if(s.endsWith(">")) {
							strPond = new StringTokenizer(s);
							if((strPond.countTokens()!=4 || 
									!s.contains("type") || 
									!s.contains("valuemin") 
									|| !s.contains("valuemax")) 
									&& (strPond.countTokens()!=3 
											|| !s.contains("type") 
											|| !s.contains("value="))) {
								System.err.println("Incomplete or " +
										"Incorrect parameters in " +
										"</action> construct in " +
										"Gold Test File");
							}
							else {
								Vector<String> vecPond = new Vector<String>();
								int strLength = strPond.countTokens();
								if(strPond.countTokens()==3) {
									strPond.nextToken();
									vecPond.add(strPond.nextToken());
									vecPond.add(strPond.nextToken());
								}
								else {
									strPond.nextToken();
									vecPond.add(strPond.nextToken());
									vecPond.add(strPond.nextToken());
									vecPond.add(strPond.nextToken());
								}
				
								for(int i = 0;i<vecPond.size();i++)
								{	String vecStrPond = 
										vecPond.elementAt(i).toString();
									if(vecStrPond.startsWith("type="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogAction = 
												strPond.nextToken().toString();
										}
										catch(Exception e) {
											frogAction = "";
										}
									}
									if(vecStrPond.startsWith("value="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogValue = 
										Integer.parseInt(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'value' of " +
													"<action> construct is " +
													"not an Integer. " +
													"Reverting the value " +
													"to 'default' 0");
											frogValue=0;
										}
									}
									if(vecStrPond.startsWith("valuemin="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogValueMin = Integer.
												parseInt(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'valuemin' " +
													"of <action> construct " +
													"is not an Integer. " +
													"Reverting the value " +
													"to 'default' 0");
											frogValueMin=0;
										}
									}
									if(vecStrPond.startsWith("valuemax="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogValueMax = Integer.
												parseInt(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'valuemax' " +
													"of <action> construct " +
													"is not an Integer. " +
													"Reverting the value " +
													"to 'default' 0");
											frogValueMax=0;
										}
									}
								}
								if(strLength==4) {
									vecGold.set(frogID, vecGold.get(frogID)+
											frogID+" "+frogAction+" random("+
											frogValueMin+","+frogValueMax+")#");
								}
								else {
									vecGold.set(frogID, vecGold.get(frogID)+
											frogID+" "+frogAction+" "+
											frogValue+"#");
								}
							}
						}
						else {
							System.err.println("Syntax Error in </action> " +
									"construct in Gold Test File");
						}
					}
					else if(s.startsWith("</curve"))
					{	if(s.endsWith(">")) {
							strPond = new StringTokenizer(s);
							if((strPond.countTokens()!=6 || 
									!s.contains("type") || 
									!s.contains("radiusmin") 
									|| !s.contains("radiusmax") 
									|| !s.contains("degreemin") 
									|| !s.contains("degreemax")) 
									&& (strPond.countTokens()!=4 
											|| !s.contains("type") 
											|| !s.contains("radius=") 
											|| !s.contains("degree="))) {
								System.err.println("Incomplete or Incorrect " +
										"parameters in </curve> construct in " +
										"Gold Test File");
							}
							else {
								int strLength = strPond.countTokens();
								Vector<String> vecPond = new Vector<String>();
								if(strPond.countTokens()==6) {
									strPond.nextToken();
									vecPond.add(strPond.nextToken());						
									vecPond.add(strPond.nextToken());
									vecPond.add(strPond.nextToken());
									vecPond.add(strPond.nextToken());
									vecPond.add(strPond.nextToken());
								}
								else {
									strPond.nextToken();
									vecPond.add(strPond.nextToken());						
									vecPond.add(strPond.nextToken());
									vecPond.add(strPond.nextToken());
								}
			
								for(int i = 0;i<vecPond.size();i++)
								{	String vecStrPond = vecPond.
										elementAt(i).toString();
									//System.out.println(vecStrPond);
									if(vecStrPond.startsWith("type="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
										frogCurve = 
											strPond.nextToken().toString();
										}
										catch(Exception e) {
											frogCurve = "";
										}
									}
									if(vecStrPond.startsWith("radius="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogRadius = Integer.
												parseInt(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'radius' " +
													"of <curve> construct " +
													"is not an Integer. " +
													"Reverting the value " +
													"to 'default' 0");
											frogRadius=0;
										}
									}
									if(vecStrPond.startsWith("radiusmin="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogRadiusMin = Integer.
												parseInt(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'radiusmin'" +
													" of <curve> construct" +
													" is not an Integer. " +
													"Reverting the value to" +
													" 'default' 0");
											frogRadiusMin=0;
										}
									}
									if(vecStrPond.startsWith("radiusmax="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogRadiusMax = 
												Integer.
												parseInt(strPond.nextToken());
										}
										catch (Exception nfe) {
											System.err.println("'radiusmax'" +
													" of <curve> construct " +
													"is not an Integer. " +
													"Reverting the value " +
													"to 'default' 0");
											frogRadiusMax=0;
										}
									}
									if(vecStrPond.startsWith("degree="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogDegree = Integer.
												parseInt(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'degree' " +
													"of <curve> construct " +
													"is not an Integer. " +
													"Reverting the value " +
													"to 'default' 0");
											frogDegree=0;
										}
									}
									if(vecStrPond.startsWith("degreemin="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogDegreeMin = 
												Integer.
												parseInt(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'degreemin'" +
													" of <curve> construct" +
													" is not an Integer. " +
													"Reverting the value to" +
													" 'default' 0");
											frogDegreeMin=0;
										}
									}
									if(vecStrPond.startsWith("degreemax="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
										frogDegreeMax = 
											Integer.
												parseInt(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'degreemax'" +
													" of <curve> construct " +
													"is not an Integer. " +
													"Reverting the value " +
													"to 'default' 0");
											frogDegreeMax=0;
										}
									}
								}
								if(strLength==6) {
									vecGold.set(frogID, vecGold.get(frogID)+
											frogID+" "+frogCurve+" " +
													"random_radius("+
													frogRadiusMin+","+
													frogRadiusMax+") " +
															"random_degree" +
															"("+frogDegreeMin+
															","+frogDegreeMax+
															")#");
								}
								else {
									vecGold.set(frogID, vecGold.get(frogID)+
											frogID+" "+frogCurve+" "+
											frogRadius+","+frogDegree+"#");
								}
							}
						}
						else {
							System.err.println("Syntax Error in </curve>" +
									" construct in Gold Test File");
						}
					}
					else if(s.startsWith("</goto"))
					{	if(s.endsWith(">")) {
							strPond = new StringTokenizer(s);
							if((strPond.countTokens()!=5 || 
									!s.contains("xvaluemin") ||
									!s.contains("xvaluemax") 
									|| !s.contains("yvaluemin") 
									|| !s.contains("yvaluemax")) 
									&& ((strPond.countTokens()!=3 
											|| !s.contains("xvalue=") 
											|| !s.contains("yvalue=")))) {
								System.err.println("Incomplete or Incorrect" +
										" parameters in </goto> construct" +
										" in Gold Test File");
							}
							else {
								int strLength = strPond.countTokens();
								Vector<String> vecPond = new Vector<String>();
								if(strPond.countTokens()==5) {
									strPond.nextToken();
									vecPond.add(strPond.nextToken());						
									vecPond.add(strPond.nextToken());
									vecPond.add(strPond.nextToken());
									vecPond.add(strPond.nextToken());
								}
								else {
									strPond.nextToken();
									vecPond.add(strPond.nextToken());						
									vecPond.add(strPond.nextToken());
								}
		
								for(int i = 0;i<vecPond.size();i++)
								{	String vecStrPond = 
										vecPond.elementAt(i).toString();
									if(vecStrPond.startsWith("xvalue="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogX = 
												Integer.parseInt
													(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'xvalue' of" +
													" <goto> construct is not" +
													" an Integer. Reverting" +
													" the value to 'default'" +
													" 0");
											frogX=0;
										}
									}
									if(vecStrPond.startsWith("xvaluemin="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogXMin = 
												Integer.parseInt
													(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'xvaluemin'" +
													" of <goto> construct is" +
													" not an Integer. " +
													"Reverting the value" +
													" to 'default' 0");
											frogXMin=0;
										}
									}
									if(vecStrPond.startsWith("xvaluemax="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try{
											frogXMax = 
												Integer.parseInt
													(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'xvaluemax'" +
													" of <goto> construct is" +
													" not an Integer. " +
													"Reverting the value to" +
													" 'default' 0");
											frogXMax=0;
										}
									}
									if(vecStrPond.startsWith("yvalue="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogY = 
												Integer.parseInt
													(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'yvalue' of" +
													" <goto> construct is not" +
													" an Integer. Reverting" +
													" the value to " +
													"'default' 0");
											frogY=0;
										}
									}
									if(vecStrPond.startsWith("yvaluemin="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogYMin = 
												Integer.parseInt
													(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'yvaluemin'" +
													" of <goto> construct is" +
													" not an Integer. " +
													"Reverting the value to" +
													" 'default' 0");
											frogYMin=0;
										}
									}	
									if(vecStrPond.startsWith("yvaluemax="))
									{	strPond = new 
											StringTokenizer(vecStrPond,"\"");
										strPond.nextToken();
										try {
											frogYMax = 
												Integer.parseInt
													(strPond.nextToken());
										}
										catch(Exception nfe) {
											System.err.println("'yvaluemax' " +
													"of <goto> construct is " +
													"not an Integer. " +
													"Reverting the value " +
													"to 'default' 0");
											frogYMax=0;
										}
									}
								}
								if(strLength==5) {
									vecGold.set(frogID, vecGold.get(frogID)+
											frogID+" goto random_x("+frogXMin+
											","+frogXMax+") random_y("+
											frogYMin+","+frogYMax+")#");
								}
								else {
									vecGold.set(frogID, vecGold.get(frogID)+
											frogID+" goto "+frogX+","+
											frogY+"#");
								}
							}
						}
						else {
							System.err.println("Syntax Error in </goto> " +
									"construct in Gold Test File");
						}
					}
					else if(s.equals("</center>"))
					{	vecGold.set(frogID, vecGold.get(frogID)+frogID+
							" center#");
					}
					else if(s.equals("</startdraw>"))
					{	vecGold.set(frogID, vecGold.get(frogID)+frogID+
							" startdraw#");
					}
					else if(s.equals("</stopdraw>"))
					{	vecGold.set(frogID, vecGold.get(frogID)+frogID+
							" stopdraw#");
					}
					else if(s.equals("</pond>"))
					{	pond--;
					}
					else if(s.equals("</frog>"))
					{	vecGold.set(frogID, vecGold.get(frogID)+frogID+" }#");
						frog--;
					}
					else {
						System.err.println(s+"=>Bad Command");
					}
				}
			}
			
		}
		catch(Exception e)
		{	System.err.println("Exception error in Gold: "+e.getMessage());
		}
		File f = new File("validation/semantics/test-standard/test.txt");
		f.delete();
	}
	
	/**
	 * The comparer function deals with traversing the Vector hosting the debug
	 * messages and the Vector hosting the test-cases written by the user with
	 * respect to the delimiter "#". For every one traversal of debug vector, a
	 *  corresponding traversal is done on the gold vector till the end of
	 *  both the vectors and then comparison result is shown.
	 * */
	public String comparer() {
		String result = "";
		if(frog==0 && pond==0 && xGoldPondSize==xPondSize && 
				yGoldPondSize==yPondSize && 
				goldPondColor.equalsIgnoreCase(pondColor)) {
			if(vecGold.size() == vecDebug.size()) 
				for(int i=1;i<=goldCount;i++) {
					StringTokenizer strGold = new 
						StringTokenizer(vecGold.get(i).toString(),"#");
					StringTokenizer strDebug = new 
						StringTokenizer(vecDebug.get(i).toString(),"#");
					while(strGold.hasMoreTokens() && 
							strDebug.hasMoreTokens()) {
						String strgold = strGold.nextToken();
						String strdebug = strDebug.nextToken();
						if(strdebug.contains("new")) {
							if(strgold.equalsIgnoreCase(strdebug)) {
								result = "PASS";	
							}
							else {
								System.err.println("Mismatch error with" +
										" 'new' construct");
								return result = "FAIL";
							}
						}
						else if(strdebug.contains("{")) {
							if(strgold.equalsIgnoreCase(strdebug)) {
								result = "PASS";
							}
							else {
								System.err.println("Mismatch error with '{'" +
										" construct");
								return result = "FAIL";
							}
						}
						else if(strdebug.contains("}")) {
							if(strgold.equalsIgnoreCase(strdebug)) {
								result = "PASS";
							}
							else {
								System.err.println("Mismatch error with '}'" +
										" construct");
								return result = "FAIL";
							}
						}
						else if(strdebug.contains("frogcolor")) {
							if(strgold.toLowerCase().
									equals(strdebug.toLowerCase())) {
								result = "PASS";
							}
							else {
								System.err.println("Mismatch error with" +
										" 'frogcolor' construct");
								return result = "FAIL";
							}
						}
						else if(strdebug.contains("center")) {
							if(strgold.equalsIgnoreCase(strdebug)) {
								result = "PASS";
							}
							else {
								System.err.println("Mismatch error with" +
										" 'center' construct");
								return result = "FAIL";
							}
						}
						else if(strdebug.contains("startdraw")) {
							if(strgold.equalsIgnoreCase(strdebug)) {
								result = "PASS";
							}
							else {
								System.err.println("Mismatch error with" +
										" 'startdraw' construct");
								return result = "FAIL";
							}
						}
						else if(strdebug.contains("stopdraw")) {
							if(strgold.equalsIgnoreCase(strdebug)) {
								result = "PASS";
							}
							else {
								System.err.println("Mismatch error with" +
										" 'stopdraw' construct");
								return result = "FAIL"; 
							}
						}
						else if(strdebug.contains("speed")) {
							if(strgold.equalsIgnoreCase(strdebug)) {
								result = "PASS";
							}
							else {
								System.err.println("Mismatch error with" +
										" 'frogspeed' construct");
								return result = "FAIL";
							}
						}
						else if(strdebug.contains("forward")) {
							if(strdebug.contains("forward") && 
										strgold.contains("forward")) {
								StringTokenizer strGoldForward = new 
										StringTokenizer(strgold);
								StringTokenizer strDebugForward = new 
										StringTokenizer(strdebug);
							
								String strdebugforward = 
									strDebugForward.nextToken()+" "+
										strDebugForward.nextToken();
								int debugVal = Integer.parseInt
										(strDebugForward.nextToken());
								
								String strgoldforward = 
										strGoldForward.nextToken()+" "+
										strGoldForward.nextToken();
								String check = strGoldForward.nextToken();
								if(check.contains("random(") && 
										check.endsWith(")")) {
									StringTokenizer strGoldForwardRandom = 
											new StringTokenizer(check,"(");
									strGoldForwardRandom.nextToken();
									StringTokenizer strGoldForwardRandomValue = 
											new StringTokenizer
											(strGoldForwardRandom.nextToken()
													,",");
									int goldVal1 = Integer.parseInt
										(strGoldForwardRandomValue.nextToken());
									StringTokenizer strGoldForwardRandomValueMax
									= new StringTokenizer
									(strGoldForwardRandomValue.nextToken(),")");
									
									int goldVal2 = Integer.parseInt
									(strGoldForwardRandomValueMax.nextToken());
									
									if(strgoldforward.equalsIgnoreCase
											(strdebugforward) && 
											debugVal>=goldVal1 && 
											debugVal<=goldVal2) {
										result = "PASS";
									}
									else {
										System.err.println("Error at " +
												"'forward' construct " +
												"in Gold Test File ");
										return result = "FAIL";
									}
								}
								else {
									int goldVal =Integer.parseInt(check.trim());
									
									if(strgoldforward.equalsIgnoreCase
											(strdebugforward) && 
											debugVal==goldVal) {
										result = "PASS";
									}
									else {
										System.err.println("Error at " +
												"'forward' construct " +
												"in Gold Test File ");
										return result = "FAIL";
									}
								}
							}
							else {
								System.err.println("Mismatch error with " +
										"'forward' construct");
								return result = "FAIL";
							}
						}
						else if(strdebug.contains("turnright")) {
							if(strdebug.contains("turnright") && 
									strgold.contains("turnright")) {
								StringTokenizer strGoldTurn = new 
									StringTokenizer(strgold);
								StringTokenizer strDebugTurn = new 
									StringTokenizer(strdebug);
								
								String strdebugturn = strDebugTurn.nextToken()+
									" "+strDebugTurn.nextToken();
								int debugVal = Integer.parseInt
									(strDebugTurn.nextToken());
								
								String strgoldturn = strGoldTurn.nextToken()+" "
									+strGoldTurn.nextToken();
								String check = strGoldTurn.nextToken();
								if(check.contains("random(") && 
											check.endsWith(")")) {
									StringTokenizer strGoldTurnRandom = 
											new StringTokenizer(check,"(");
									strGoldTurnRandom.nextToken();
									StringTokenizer strGoldTurnRandomValue = 
											new StringTokenizer
											(strGoldTurnRandom.nextToken(),",");
									int goldVal1 = Integer.parseInt
										(strGoldTurnRandomValue.nextToken());
									StringTokenizer strGoldTurnRandomValueMax = 
										new StringTokenizer
										(strGoldTurnRandomValue.
												nextToken(),")");
									int goldVal2 = Integer.parseInt
										(strGoldTurnRandomValueMax.nextToken());
									
									if(strgoldturn.equalsIgnoreCase
											(strdebugturn) && 
											debugVal>=goldVal1 && 
											debugVal<=goldVal2) {
										result = "PASS";
									}
									else {
										System.err.println("Error at " +
												"'turnright' construct " +
												"in Gold Test File ");
										return result = "FAIL";
									}
								}
								else {
									int goldVal =Integer.parseInt(check.trim());
									
									if(strgoldturn.equalsIgnoreCase
											(strdebugturn) && 
											debugVal==goldVal) {
										result = "PASS";
									}
									else {
										System.err.println("Error at " +
												"'turnright' construct " +
												"in Gold Test File ");
										return result = "FAIL";
									}
								}
							
							}
							else {
								System.err.println("Mismatch error with " +
										"'turnright' construct");
								return result = "FAIL";
							}
						}
						else if(strdebug.contains("turnleft")) {
							if(strdebug.contains("turnleft") && 
									strgold.contains("turnleft")) {
								StringTokenizer strGoldTurn = new 
									StringTokenizer(strgold);
								StringTokenizer strDebugTurn = new 
									StringTokenizer(strdebug);
							
								String strdebugturn = strDebugTurn.nextToken()+
									" "+strDebugTurn.nextToken();
								int debugVal = Integer.parseInt
									(strDebugTurn.nextToken());
								
								String strgoldturn = strGoldTurn.nextToken()+
									" "+strGoldTurn.nextToken();
								String check = strGoldTurn.nextToken();
								if(check.contains("random(") && 
										check.endsWith(")")) {
									StringTokenizer strGoldTurnRandom = 
											new StringTokenizer(check,"(");
									strGoldTurnRandom.nextToken();
									StringTokenizer strGoldTurnRandomValue = 
											new StringTokenizer
											(strGoldTurnRandom.nextToken(),",");
									int goldVal1 = 
										Integer.parseInt
										(strGoldTurnRandomValue.nextToken());
									StringTokenizer strGoldTurnRandomValueMax = 
										new StringTokenizer
										(strGoldTurnRandomValue.nextToken(),
												")");
									int goldVal2 = 
										Integer.parseInt(
												strGoldTurnRandomValueMax.
												nextToken());
									
									if(strgoldturn.equalsIgnoreCase
											(strdebugturn) && debugVal>=goldVal1
											&& debugVal<=goldVal2) {
										result = "PASS";
									}
									else {
											System.err.println("Error at " +
													"'turnleft' construct " +
													"in Gold Test File ");
											return result = "FAIL";
									}
								}
								else {
									int goldVal =Integer.parseInt(check.trim());
									
									if(strgoldturn.equalsIgnoreCase
											(strdebugturn) && 
											debugVal==goldVal) {
										result = "PASS";
									}
									else {
										System.err.println("Error at " +
												"'turnleft' construct " +
												"in Gold Test File ");
										return result = "FAIL";
									}
								}
							
							}
							else {
								System.err.println("Mismatch error with " +
										"'turnleft' construct");
								return result = "FAIL";
							}
						}
						else if(strdebug.contains("rightcurve")) {
							if(strdebug.contains("rightcurve") && 
									strgold.contains("rightcurve")) {
								StringTokenizer strGoldCurve = new 
										StringTokenizer(strgold);
								StringTokenizer strDebugCurve = new 
										StringTokenizer(strdebug);
							
								String strdebugcurve = 
										strDebugCurve.nextToken()+" "
										+strDebugCurve.nextToken();
								StringTokenizer strDebugCurveValue = new 
									StringTokenizer
										(strDebugCurve.nextToken(),",");
								int debugRadiusVal = 
									Integer.parseInt
										(strDebugCurveValue.nextToken());
								int debugDegreeVal = 
									Integer.parseInt
										(strDebugCurveValue.nextToken());
								
								String strgoldcurve = strGoldCurve.nextToken()+
									" "+strGoldCurve.nextToken();
								
								if(strGoldCurve.countTokens()==1) {
									StringTokenizer strGoldCurveRandom = new 
										StringTokenizer
										(strGoldCurve.nextToken(),",");
									int goldVal1 = Integer.parseInt
											(strGoldCurveRandom.nextToken());
									int goldVal2 = Integer.parseInt
											(strGoldCurveRandom.nextToken());
									
									if(strgoldcurve.equalsIgnoreCase
											(strdebugcurve) && 
											debugRadiusVal==goldVal1 
											&& debugDegreeVal==goldVal2) {
										result = "PASS";
									}
									else {
										System.err.println("Error at " +
												"'rightcurve' construct " +
												"in Gold Test File ");
										return result = "FAIL";
									}
								}
								else {
									StringTokenizer strGoldCurveRandom = 
										new StringTokenizer
										(strGoldCurve.nextToken(),"(");
									strGoldCurveRandom.nextToken();
									StringTokenizer 
										strGoldCurveRandomRadiusValue = 
											new StringTokenizer
											(strGoldCurveRandom.nextToken()
													,",");
									int goldVal1 = 
										Integer.parseInt
										(strGoldCurveRandomRadiusValue.
												nextToken());
									StringTokenizer 
										strGoldCurveRandomRadiusValueMax = 
											new StringTokenizer
											(strGoldCurveRandomRadiusValue.
													nextToken(),")");
									int goldVal2 = Integer.parseInt
									(strGoldCurveRandomRadiusValueMax.
											nextToken());
								
									strGoldCurveRandom = new StringTokenizer
										(strGoldCurve.nextToken(),"(");
									strGoldCurveRandom.nextToken();
									StringTokenizer 
										strGoldCurveRandomDegreeValue = 
											new StringTokenizer
											(strGoldCurveRandom.nextToken(),
													",");
									int goldVal3 = Integer.parseInt
										(strGoldCurveRandomDegreeValue.
												nextToken());
									StringTokenizer 
										strGoldCurveRandomDegreeValueMax = 
											new StringTokenizer(
												strGoldCurveRandomDegreeValue.
												nextToken(),")");
									int goldVal4 = Integer.parseInt
										(strGoldCurveRandomDegreeValueMax.
												nextToken());
									
									if(strgoldcurve.equalsIgnoreCase
											(strdebugcurve) && 
											debugRadiusVal>=goldVal1 && 
											debugRadiusVal<=goldVal2 && 
											debugDegreeVal>=goldVal3 && 
											debugDegreeVal<=goldVal4) {
										result = "PASS";
									}
									else {
										System.err.println("Error at " +
												"'rightcurve' construct " +
												"in Gold Test File ");
										return result = "FAIL";
									}
								}
									
							}
							else {
								System.err.println("Mismatch error with " +
										"'rightcurve' construct");
								return result = "FAIL";
							}
						}
						else if(strdebug.contains("leftcurve")) {
							if(strdebug.contains("leftcurve") && 
									strgold.contains("leftcurve")) {
								StringTokenizer strGoldCurve = new 
									StringTokenizer(strgold);
								StringTokenizer strDebugCurve = new 
									StringTokenizer(strdebug);
							
								String strdebugcurve = 
									strDebugCurve.nextToken()+" "+
									strDebugCurve.nextToken();
								StringTokenizer strDebugCurveValue = 
									new StringTokenizer
									(strDebugCurve.nextToken(),",");
								int debugRadiusVal = 
									Integer.parseInt
									(strDebugCurveValue.nextToken());
								int debugDegreeVal = 
									Integer.parseInt
									(strDebugCurveValue.nextToken());
								
								String strgoldcurve = strGoldCurve.nextToken()+
									" "+strGoldCurve.nextToken();
								
								if(strGoldCurve.countTokens()==1) {
									StringTokenizer strGoldCurveRandom = 
										new StringTokenizer
										(strGoldCurve.nextToken(),",");
									int goldVal1 = 
										Integer.parseInt
										(strGoldCurveRandom.nextToken());
									int goldVal2 = 
										Integer.parseInt
										(strGoldCurveRandom.nextToken());
									
									if(strgoldcurve.equalsIgnoreCase
											(strdebugcurve) && 
											debugRadiusVal==goldVal1 && 
											debugDegreeVal==goldVal2) {
										result = "PASS";
									}
									else {
										System.err.println("Error at " +
												"'rightcurve' construct in " +
												"Gold Test File ");
										return result = "FAIL";
									}
								}
								else {
									StringTokenizer strGoldCurveRandom = 
										new StringTokenizer
										(strGoldCurve.nextToken(),"(");
									strGoldCurveRandom.nextToken();
									StringTokenizer 
										strGoldCurveRandomRadiusValue = 
											new StringTokenizer
											(strGoldCurveRandom.nextToken()
													,",");
									int goldVal1 = 
										Integer.parseInt
										(strGoldCurveRandomRadiusValue.
												nextToken());
									StringTokenizer	 
										strGoldCurveRandomRadiusValueMax = 
											new StringTokenizer
											(strGoldCurveRandomRadiusValue.
													nextToken(),")");
									int goldVal2 = Integer.parseInt
										(strGoldCurveRandomRadiusValueMax.
												nextToken());
								
									strGoldCurveRandom = 
										new StringTokenizer
										(strGoldCurve.nextToken(),"(");
									strGoldCurveRandom.nextToken();
									StringTokenizer 
										strGoldCurveRandomDegreeValue = 
											new StringTokenizer
											(strGoldCurveRandom.nextToken(),
													",");
									int goldVal3 = Integer.parseInt
										(strGoldCurveRandomDegreeValue.
												nextToken());
									StringTokenizer 
										strGoldCurveRandomDegreeValueMax = 
											new StringTokenizer
											(strGoldCurveRandomDegreeValue.
													nextToken(),")");
									int goldVal4 = Integer.parseInt
										(strGoldCurveRandomDegreeValueMax.
												nextToken());
									
									if(strgoldcurve.equalsIgnoreCase
											(strdebugcurve) && 
											debugRadiusVal>=goldVal1 && 
											debugRadiusVal<=goldVal2 && 
											debugDegreeVal>=goldVal3 && 
											debugDegreeVal<=goldVal4) {
										result = "PASS";
									}
									else {
										System.err.println("Error at " +
												"'leftcurve' construct " +
												"in Gold Test File ");
										return result = "FAIL";
									}
								}				
							}
							else {
								System.err.println("Mismatch error with " +
										"'leftcurve' construct");
								return result = "FAIL";
							}
						}
						else if(strdebug.contains("goto")) {
							if(strdebug.contains("goto") && 
									strgold.contains("goto")) {
								StringTokenizer strGoldGoto = new 
									StringTokenizer(strgold);
								StringTokenizer strDebugGoto = new 
									StringTokenizer(strdebug);
							
								String strdebuggoto = strDebugGoto.nextToken()+
									" "+strDebugGoto.nextToken();
								StringTokenizer strDebugGotoValue = new 
									StringTokenizer(strDebugGoto.nextToken(),
											",");
								int debugXVal = 
									Integer.parseInt
									(strDebugGotoValue.nextToken());
								int debugYVal = 
									Integer.parseInt
									(strDebugGotoValue.nextToken());
								
								String strgoldgoto = strGoldGoto.nextToken()+
									" "+strGoldGoto.nextToken();
								
								if(strGoldGoto.countTokens()==1) {
									StringTokenizer strGoldCurveRandom = 
										new StringTokenizer(strGoldGoto.
												nextToken(),",");
									int goldVal1 = Integer.parseInt
										(strGoldCurveRandom.nextToken());
									int goldVal2 = Integer.parseInt
										(strGoldCurveRandom.nextToken());
									
									if(strgoldgoto.equalsIgnoreCase
											(strdebuggoto) && 
											debugXVal==goldVal1 && 
											debugYVal==goldVal2) {
										result = "PASS";
									}
									else {
										System.err.println("Error at " +
												"'rightcurve' construct " +
												"in Gold Test File ");
										return result = "FAIL";
									}
								}
								else {
									StringTokenizer strGoldGotoRandom = new 
										StringTokenizer
										(strGoldGoto.nextToken(),"(");
									strGoldGotoRandom.nextToken();
									StringTokenizer strGoldGotoRandomXValue 
										= new StringTokenizer
											(strGoldGotoRandom.nextToken(),",");
									int goldVal1 = 
										Integer.parseInt
										(strGoldGotoRandomXValue.nextToken());
									StringTokenizer strGoldGotoRandomXValueMax 
										= new StringTokenizer
										(strGoldGotoRandomXValue.nextToken(),
												")");
									int goldVal2 =
										Integer.parseInt
										(strGoldGotoRandomXValueMax.
												nextToken());
								
									strGoldGotoRandom = new 
										StringTokenizer(strGoldGoto.nextToken(),
											"(");
									strGoldGotoRandom.nextToken();
									StringTokenizer strGoldGotoRandomYValue = 
										new StringTokenizer(strGoldGotoRandom.
												nextToken(),",");
									int goldVal3 = Integer.parseInt
									(strGoldGotoRandomYValue.nextToken());
									StringTokenizer strGoldGotoRandomYValueMax 
									= new StringTokenizer(
											strGoldGotoRandomYValue.
											nextToken(),")");
									int goldVal4 = Integer.parseInt(
											strGoldGotoRandomYValueMax.
											nextToken());
								
									if(strgoldgoto.equalsIgnoreCase
											(strdebuggoto) && 
											debugXVal>=goldVal1 &&
											debugXVal<=goldVal2 &&
											debugYVal>=goldVal3 &&
											debugYVal<=goldVal4) {
										result = "PASS";
									}
									else {
										System.err.println("Error at 'goto' " +
												"construct in Gold Test File ");
										return result = "FAIL";
									}
								}
								
							}
							else {
								System.err.println("Mismatch error with " +
										"'goto' construct");
								return result = "FAIL";
							}
						}
					}
					/**result = "PASS";*/
				}
			else
				result = "FAIL";
		}
		else
			return result = "FAIL";
		if(pond!=0) {
			System.err.println("<pond> construct is not balanced");
			return result = "FAIL";
		}
		if(frog!=0) {
			System.err.println("<frog> construct is not balanced");
			return result = "FAIL";
		}
		vecGold.removeAllElements();
		vecDebug.removeAllElements();

		return result;
	}
	
	/**The display function is used to showcase the data present within a
	 * data structure - Vector in our case.*/
	public void display()
	{	try {
			System.out.println("Pond size:"+xPondSize+","+yPondSize+" color:"+
					pondColor);
			System.out.println("DEBUG");
		
			for(int i=1;i<=debugCount;i++)
				System.out.println(vecDebug.get(i));
			System.out.println("Pond size:"+xGoldPondSize+","+yGoldPondSize+
					" color:"+goldPondColor);
			System.out.println("GOLD");
			for(int i=1;i<=goldCount;i++)
				System.out.println(vecGold.get(i));

		}
		catch(ArrayIndexOutOfBoundsException aioobe) {
			System.err.println("Vectors are empty");
		}	
	}
}